import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: '/home',
      component: () => import('@/components/tabbar/index.vue'),
      children: [
        {
          path: '/home',
          name: 'home',
          meta: {
            title: '首页',
          },
          component: () => import('@/views/home/home-view.vue'),
        },
        {
          path: '/message',
          name: 'message',
          meta: {
            title: '消息',
          },
          component: () => import('@/views/message/message-view.vue'),
        },
        {
          path: '/my',
          name: 'my',
          meta: {
            title: '我的',
          },
          component: () => import('@/views/my/my-view.vue'),
        },
      ],
    },
    {
      path: '/message-detail',
      name: 'message-detail',
      meta: {
        title: '消息详情',
      },
      component: () => import('@/views/message-detail/message-detail-view.vue'),
    },
  ],
})

router.beforeEach((to, from, next) => {
  document.title = (to.meta.title as string) || '批零商城'
  next()
  // let user = 'zzz'
  // if (to.meta.isAuth) {
  //   if (user == 'admin') {
  //     next()
  //   } else {
  //     alert('你没有权限')
  //   }
  // } else {
  //   next()
  // }
})

export default router
